Powershell remoting exchange server 2007
Hi,
I am trying to connect to exchange server2007 remotely and execute the exchange commands
I am getting the following error
The WinRM client sent a request to an HTTP server and got a response saying the requested HTTP URL was not available. This is usually returned by a HTTP server that does not support the WS-Management protocol.
I tried different uri but not succeeded. Below is my code snippet :
string sSHELL_URI = "http://schemas.microsoft.com/powershell/Microsoft.PowerShell";
Uri objCompURI = new Uri(String.Format("http://{0}:5985/wsman", m_sServerName));
WSManConnectionInfo connectionInfo = new WSManConnectionInfo(m_objServerUri, m_SHELL_URI, m_objCreds);
connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Kerberos;
RunspacePool remoteRunspacePool = RunspaceFactory.CreateRunspacePool(1, 2, connectionInfo));
remoteRunspacePool.Open();
PowerShell objps = PowerShell.Create();
objps.AddScript(sScript);
objps.RunspacePool = remoteRunspacePool;
Collection<PSObject> results = objps.Invoke();
Thanks in Advance
Viswanath B
January 12th, 2011 2:11pm
Hi Philip,
I checked the configuration. It is same as mentioned in the article. But still I am getting the same error on Server1.
On server 2 I am getting below error.
Connecting to remote server failed with the following error message : The WinRM client received an HTTP status code of 403 from the remote WS-Management service.
Thanks,
Viswanath
Free Windows Admin Tool Kit Click here and download it now
January 12th, 2011 4:02pm
Ashish,
Thanks for the reply. I am using Exchange 2007. in 2007 I don't see any Powershell VD in IIS.
January 12th, 2011 8:30pm
Hi Ashish,
New-PowershellVirtualdirectory cmdlet doesn't work on exchange 2007. It is in specific to exchange 2010. I don't have any issues with exchange 2010. My code is working fine for 2010. Problem is only with powershell remoting to 2007.
Thanks,
Viswanath B
January 17th, 2011 9:24am
See
With Exchange 2007 you have to execute the cmdlets locally on the machine where the code is running from that means that machine needs to exist is a security context that will allow you run the Exchange Management Shell eg installed as per
http://technet.microsoft.com/en-us/library/bb232090%28EXCHG.80%29.aspx. If there is no Trust between the domains your machine is in and Exchange Server and you can't logon onto the machine where the code is running with
a user that has been deletegated Exchange Administration rights then your code wont work with 2007 because there is no ability to specify alternate credentials in the EMS. You need to have the code running from a machine where the secruity context is availible.
Another option if this isn't possible for you is that the log files themselves are plain text so you can parse the directly eg using something like Logparser the problem is that these files can be very large so its not something unless your log
files are small that you want to attempt over a network.
By
Pah Finder
Free Windows Admin Tool Kit Click here and download it now
January 22nd, 2011 8:33am
This is one the most confusing parts for remote admistration for me too.
All the documentation that I can find says you use the:
WSManConnectionInfo connectionInfo = new WSManConnectionInfo(m_objServerUri, m_SHELL_URI, m_objCreds);
for Exchange 2010
and
rc = RunspaceConfiguration::Create();
snapEx = gcnew PSSnapInException();
PSSnapInInfo^ info = rc->AddPSSnapIn(
"Microsoft.Exchange.Management.PowerShell.Admin", snapEx);
myRunSpace = RunspaceFactory::CreateRunspace(rc);
myRunSpace->Open();
for exchange 2007. This also means you need to install the exchange manage tools locally on the client so it can find the snapin code locally.
One of the biggest differences between 2007 and 2010 was that 2007 needs the snapin and the 2010 must be run through a connection.
So for the 2007 version, you need to specify the destination server as a parameter to the commands of intests.
Example:
String^ cmd;
cmd = "get-exchangeserver";
Command^ newMbx = gcnew Command(cmd);
// Add the command we've constructed
Pipeline^ pipeLine = myRunSpace->CreatePipeline();
pipeLine->Commands->Add(newMbx);
newMbx->Parameters->Add("identity", gcnew String("MyServerMachine") );
// Execute the pipeline and save the objects returned.
results = pipeLine->Invoke();
sample code for 2010 that works for me:
rc = RunspaceConfiguration::Create();
System::Security::SecureString pw;
String ^spw = gcnew String("test");
array<wchar_t> ^c = spw->ToCharArray();
for(int i=0; i<spw->Length; i++ ){
wchar_t a = c[i];
pw.AppendChar(a);
}
// Destination exchange server
Uri ^sDestServer = gcnew Uri(String::Format( gcnew String("https://{0}/powershell"), gcnew String(sdi.sMachineName.c_str())) );
WSManConnectionInfo ^connectionInfo = gcnew WSManConnectionInfo(
sDestServer,
gcnew String("http://schemas.microsoft.com/powershell/Microsoft.Exchange"),
gcnew PSCredential(gcnew String("user1"), %pw ) );
connectionInfo->AuthenticationMechanism = AuthenticationMechanism::NegotiateWithImplicitCredential;
// must be in constructor:: connectionInfo->ShellUri = "microsoft.exchange";
connectionInfo->SkipCACheck = true;
connectionInfo->SkipCNCheck = true;
connectionInfo->SkipRevocationCheck = true;
myRunSpace = RunspaceFactory::CreateRunspace(connectionInfo);
myRunSpace->Open();
February 11th, 2011 2:58pm